<!DOCTYPE html>
<html>
<head>
<link rel="icon" href="data:,">
<title>Set PreValue</title>
<meta charset="utf-8">
	
<style>
h1 {font-size: 2em;}
h2 {font-size: 1.5em;}
h3 {font-size: 1.2em;}
p {font-size: 1em;}

div {
	width: 200px;
    padding: 10px 5px;
    display: inline-block;
    border: 1px solid #ccc;
    font-size: 16px;
	max-height: 35px;	
}

input[type=number] {
	width: 125px;
	padding: 10px 5px;
	display: inline-block;
	border: 1px solid #ccc;
	font-size: 16px; 
}

.button {
	padding: 10px 20px;
    width: 211px;
	font-size: 16px;	
}
</style>	
	
</head>

<body style="font-family: arial; padding: 0px 10px;">
<h3>Set the previous value for consistency check and substitution for NaN</h3>

<class id="Numbers_text" style="font-size: 120%; color:black;"><b>Choose Number: </b>
<select id="Numbers_value1" onchange="numberChanged()">
	<option value="0" selected>default</option>
	<option value="1" >NT</option>
	<option value="2" >HT</option>
</select>
</class>


<table style="width:100%">
  <tr>
    <h3>Current Value:</h3><p>
	<div id="prevalue"></div>
  <h3>Set Value:</h3><p>
    Input (Format = 123.456):<p>
	PreValue: 
	 <input type="number" id="myInput" name="myInput"
           pattern="[0-9]+([\.,][0-9]+)?" step="0.001"
            title="This should be a number with up to 4 decimal places.">
	<p></p>
	<button class="button" type="button" onclick="setprevalue()">Set PreValue</button>
  </tr>	
  <tr>
    <h3>Result:</h3><p>
	<div id="result" readonly></div>
  </tr>	 

</table>

</body></html>


<script type="text/javascript" src="./gethost.js"></script> 
<script type="text/javascript" src="./readconfigcommon.js"></script>  
<script type="text/javascript" src="./readconfigparam.js"></script>  

<script type="text/javascript">
 	var basepath = "http://192.168.178.22"; 
  var	NUMBERS;

function setprevalue() {
	var inputVal = document.getElementById("myInput").value;
	var sel = document.getElementById("Numbers_value1");
	var _number = sel.options[sel.selectedIndex].text;  
	inputVal = inputVal.replace(",", ".");
  	var xhttp = new XMLHttpRequest();
    try {
          url = basepath + "/setPreValue.html?value=" + inputVal + "&numbers=" + _number;     
          xhttp.open("GET", url, false);
          xhttp.send();
          response = xhttp.responseText;
          document.getElementById("result").innerHTML=response;
     }
     catch (error)
     {
     //          alert("Deleting Config.ini failed");
     }
}

function loadPrevalue(_basepath) {
    var sel = document.getElementById("Numbers_value1");
    var _number = sel.options[sel.selectedIndex].text;  

     var xhttp = new XMLHttpRequest();
     try {
          url = _basepath + '/setPreValue.html?numbers=' + _number;     
          xhttp.open("GET", url, false);
          xhttp.send();
          response = xhttp.responseText;
          document.getElementById("prevalue").innerHTML=response;
     }
     catch (error)
     {
     //          alert("Deleting Config.ini failed");
     }
     return true;
}


function numberChanged(){
  loadPrevalue(basepath);
}

function UpdateNUMBERS(_sel){
    zw = getNUMBERInfo();

    index = 0;

    var _index = document.getElementById("Numbers_value1");
    while (_index.length){
        _index.remove(0);
    }

    for (var i = 0; i < zw.length; ++i){
        var option = document.createElement("option");
        option.text = zw[i]["name"];
        option.value = i;
        _index.add(option); 

        if (typeof _sel !== 'undefined') {
            if (zw[i]["name"] == _sel)
                index = i
        }
    }
    _index.selectedIndex = index;

    loadPrevalue(basepath);
}


function init(){
	basepath = getbasepath();
  loadConfig(basepath); 
  ParseConfig();
  UpdateNUMBERS();
  loadPrevalue(basepath);
}

init();
</script>
